//
//  ClassifyCaremeViewController.m
//  UI_xiangmu
//
//  Created by dllo on 15/4/24.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "ClassifyCaremeViewController.h"
#import "AFHTTPRequestOperationManager.h"
#import "UIImageView+WebCache.h"
#import "ClassifyModelOther.h"
#import "ClassifyotherCell.h"
#import "detailCamereViewController.h"
#import "MJRefresh.h"
@interface ClassifyCaremeViewController ()

@property(nonatomic,retain)NSMutableArray *modelArr;

@property(nonatomic,assign)NSInteger page;

@end

@implementation ClassifyCaremeViewController

-(void)data
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString *str = [NSString stringWithFormat:@"http://manhua.haomee.cn/?m=Api&ios=23&pad=0&a=listByType&id=%@&page=%ld&limit=30&order=1",self.canshu,self.page];
    [manager GET:str parameters:self success:^(AFHTTPRequestOperation *operation, id responseObject) {
        self.modelArr = [NSMutableArray array];
        NSMutableDictionary *dic = responseObject;
        NSMutableArray *arr = [dic objectForKey:@"list"];
        for (NSMutableDictionary *dic in arr) {
            ClassifyModelOther *model = [[ClassifyModelOther alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.modelArr addObject:model];
            [model release];
        }
        [self.myTableView reloadData];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"解析失败");
    }];
    
    
}

- (void)method
{
    [self.myTableView addLegendHeaderWithRefreshingBlock:^{
        [self.modelArr removeAllObjects];
        self.page = 1;
        [self data];
        [self.myTableView reloadData];
        [self.myTableView.header endRefreshing];
    }];
    [self.myTableView.legendHeader beginRefreshing];
    [self.myTableView addLegendFooterWithRefreshingBlock:^{
        self.page++;
        [self data];
        [self.myTableView reloadData];
        [self.myTableView.footer endRefreshing];
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.page = 1;
    // Do any additional setup after loading the view.
    [self data];
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.view addSubview:self.myTableView];
    self.myTableView.rowHeight = 120;
    [self method];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.modelArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse = @"reuse";
    ClassifyotherCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (cell == nil) {
        cell = [[[ClassifyotherCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
    }
    NSURL *url = [NSURL URLWithString:[self.modelArr[indexPath.row] cover]];
    [cell.myimage sd_setImageWithURL:url];
    cell.namelabel.text = [self.modelArr[indexPath.row] name];
    if ([[self.modelArr[indexPath.row] is_over] isEqual:@"1"]) {
        NSString *str = [NSString stringWithFormat:@"全%@集",[self.modelArr[indexPath.row] cur_num]];
        cell.jishulabel.text =str;
        
    }else{
        NSString *str = [NSString stringWithFormat:@"更新至%@集",[self.modelArr[indexPath.row] cur_num]];
        cell.jishulabel.text =str;

    }
    NSString *str = [NSString stringWithFormat:@"%@分",[self.modelArr[indexPath.row]score]];
    cell.scorelabel.text = str;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    detailCamereViewController *de = [[detailCamereViewController alloc] init];
    de.canshu = [self.modelArr[indexPath.row] video_id];
    de.canshu = [NSString stringWithFormat:@"http://manhua.haomee.cn/?m=Api&ios=23&pad=0&a=getInfo&video_id=%@&uid=(null)",de.canshu];
    [self.navigationController pushViewController:de animated:YES];
    [de release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
